﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Delta
{
    public partial class LayoutForm : Form
    {
        public Form1 form1;
        Point Chosedposition;
        public List<List<int>> ListModel = new List<List<int>>();
        public List<UITextBox> listTextBox = new List<UITextBox>();     
        public int layerText1, layerText2, layerText3, layerText4, layerText5, layerText6, layerText7, layerText8, layerText9, layerText10, layerText11, layerText12, layerText13, layerText14, layerText15, layerText16, layerText17, layerText18, layerText19, layerText20;
        public List<int> listlayerText = new List<int>();
        public bool[] ProductTypeUsed = new bool[8];
        UITextBox textBox;
        public LayoutForm(Form1 form)
        {
            InitializeComponent();
            form1 = form;
            listlayerText.Add(layerText1);
            listlayerText.Add(layerText2);
            listlayerText.Add(layerText3);
            listlayerText.Add(layerText4);
            listlayerText.Add(layerText5);
            listlayerText.Add(layerText6);
            listlayerText.Add(layerText7);
            listlayerText.Add(layerText8);
            listlayerText.Add(layerText9);
            listlayerText.Add(layerText10);
            listlayerText.Add(layerText11);
            listlayerText.Add(layerText12);
            listlayerText.Add(layerText13);
            listlayerText.Add(layerText14);
            listlayerText.Add(layerText15);
            listlayerText.Add(layerText16);
            listlayerText.Add(layerText17);
            listlayerText.Add(layerText18);
            listlayerText.Add(layerText19);
            listlayerText.Add(layerText20);

            ListModel.Add(form1.layoutInformation.ModelNO11);
            ListModel.Add(form1.layoutInformation.ModelNO12);
            ListModel.Add(form1.layoutInformation.ModelNO13);
            ListModel.Add(form1.layoutInformation.ModelNO14);
            ListModel.Add(form1.layoutInformation.ModelNO15);
            ListModel.Add(form1.layoutInformation.ModelNO16);
            ListModel.Add(form1.layoutInformation.ModelNO17);
            ListModel.Add(form1.layoutInformation.ModelNO18);
            ListModel.Add(form1.layoutInformation.ModelNO19);
            ListModel.Add(form1.layoutInformation.ModelNO110);
            ListModel.Add(form1.layoutInformation.ModelNO111);
            ListModel.Add(form1.layoutInformation.ModelNO112);
            ListModel.Add(form1.layoutInformation.ModelNO113);
            ListModel.Add(form1.layoutInformation.ModelNO114);
            ListModel.Add(form1.layoutInformation.ModelNO115);
            ListModel.Add(form1.layoutInformation.ModelNO116);
            ListModel.Add(form1.layoutInformation.ModelNO117);
            ListModel.Add(form1.layoutInformation.ModelNO118);
            ListModel.Add(form1.layoutInformation.ModelNO119);
            ListModel.Add(form1.layoutInformation.ModelNO120);

            ListModel.Add(form1.layoutInformation.ModelNO21);
            ListModel.Add(form1.layoutInformation.ModelNO22);
            ListModel.Add(form1.layoutInformation.ModelNO23);
            ListModel.Add(form1.layoutInformation.ModelNO24);
            ListModel.Add(form1.layoutInformation.ModelNO25);
            ListModel.Add(form1.layoutInformation.ModelNO26);
            ListModel.Add(form1.layoutInformation.ModelNO27);
            ListModel.Add(form1.layoutInformation.ModelNO28);
            ListModel.Add(form1.layoutInformation.ModelNO29);
            ListModel.Add(form1.layoutInformation.ModelNO210);
            ListModel.Add(form1.layoutInformation.ModelNO211);
            ListModel.Add(form1.layoutInformation.ModelNO212);
            ListModel.Add(form1.layoutInformation.ModelNO213);
            ListModel.Add(form1.layoutInformation.ModelNO214);
            ListModel.Add(form1.layoutInformation.ModelNO215);
            ListModel.Add(form1.layoutInformation.ModelNO216);
            ListModel.Add(form1.layoutInformation.ModelNO217);
            ListModel.Add(form1.layoutInformation.ModelNO218);
            ListModel.Add(form1.layoutInformation.ModelNO219);
            ListModel.Add(form1.layoutInformation.ModelNO220);

            ListModel.Add(form1.layoutInformation.ModelNO31);
            ListModel.Add(form1.layoutInformation.ModelNO32);
            ListModel.Add(form1.layoutInformation.ModelNO33);
            ListModel.Add(form1.layoutInformation.ModelNO34);
            ListModel.Add(form1.layoutInformation.ModelNO35);
            ListModel.Add(form1.layoutInformation.ModelNO36);
            ListModel.Add(form1.layoutInformation.ModelNO37);
            ListModel.Add(form1.layoutInformation.ModelNO38);
            ListModel.Add(form1.layoutInformation.ModelNO39);
            ListModel.Add(form1.layoutInformation.ModelNO310);
            ListModel.Add(form1.layoutInformation.ModelNO311);
            ListModel.Add(form1.layoutInformation.ModelNO312);
            ListModel.Add(form1.layoutInformation.ModelNO313);
            ListModel.Add(form1.layoutInformation.ModelNO314);
            ListModel.Add(form1.layoutInformation.ModelNO315);
            ListModel.Add(form1.layoutInformation.ModelNO316);
            ListModel.Add(form1.layoutInformation.ModelNO317);
            ListModel.Add(form1.layoutInformation.ModelNO318);
            ListModel.Add(form1.layoutInformation.ModelNO319);
            ListModel.Add(form1.layoutInformation.ModelNO320);

            ListModel.Add(form1.layoutInformation.ModelNO41);
            ListModel.Add(form1.layoutInformation.ModelNO42);
            ListModel.Add(form1.layoutInformation.ModelNO43);
            ListModel.Add(form1.layoutInformation.ModelNO44);
            ListModel.Add(form1.layoutInformation.ModelNO45);
            ListModel.Add(form1.layoutInformation.ModelNO46);
            ListModel.Add(form1.layoutInformation.ModelNO47);
            ListModel.Add(form1.layoutInformation.ModelNO48);
            ListModel.Add(form1.layoutInformation.ModelNO49);
            ListModel.Add(form1.layoutInformation.ModelNO410);
            ListModel.Add(form1.layoutInformation.ModelNO411);
            ListModel.Add(form1.layoutInformation.ModelNO412);
            ListModel.Add(form1.layoutInformation.ModelNO413);
            ListModel.Add(form1.layoutInformation.ModelNO414);
            ListModel.Add(form1.layoutInformation.ModelNO415);
            ListModel.Add(form1.layoutInformation.ModelNO416);
            ListModel.Add(form1.layoutInformation.ModelNO417);
            ListModel.Add(form1.layoutInformation.ModelNO418);
            ListModel.Add(form1.layoutInformation.ModelNO419);
            ListModel.Add(form1.layoutInformation.ModelNO420);

            ListModel.Add(form1.layoutInformation.ModelNO51);
            ListModel.Add(form1.layoutInformation.ModelNO52);
            ListModel.Add(form1.layoutInformation.ModelNO53);
            ListModel.Add(form1.layoutInformation.ModelNO54);
            ListModel.Add(form1.layoutInformation.ModelNO55);
            ListModel.Add(form1.layoutInformation.ModelNO56);
            ListModel.Add(form1.layoutInformation.ModelNO57);
            ListModel.Add(form1.layoutInformation.ModelNO58);
            ListModel.Add(form1.layoutInformation.ModelNO59);
            ListModel.Add(form1.layoutInformation.ModelNO510);
            ListModel.Add(form1.layoutInformation.ModelNO511);
            ListModel.Add(form1.layoutInformation.ModelNO512);
            ListModel.Add(form1.layoutInformation.ModelNO513);
            ListModel.Add(form1.layoutInformation.ModelNO514);
            ListModel.Add(form1.layoutInformation.ModelNO515);
            ListModel.Add(form1.layoutInformation.ModelNO516);
            ListModel.Add(form1.layoutInformation.ModelNO517);
            ListModel.Add(form1.layoutInformation.ModelNO518);
            ListModel.Add(form1.layoutInformation.ModelNO519);
            ListModel.Add(form1.layoutInformation.ModelNO520);

            ListModel.Add(form1.layoutInformation.ModelNO61);
            ListModel.Add(form1.layoutInformation.ModelNO62);
            ListModel.Add(form1.layoutInformation.ModelNO63);
            ListModel.Add(form1.layoutInformation.ModelNO64);
            ListModel.Add(form1.layoutInformation.ModelNO65);
            ListModel.Add(form1.layoutInformation.ModelNO66);
            ListModel.Add(form1.layoutInformation.ModelNO67);
            ListModel.Add(form1.layoutInformation.ModelNO68);
            ListModel.Add(form1.layoutInformation.ModelNO69);
            ListModel.Add(form1.layoutInformation.ModelNO610);
            ListModel.Add(form1.layoutInformation.ModelNO611);
            ListModel.Add(form1.layoutInformation.ModelNO612);
            ListModel.Add(form1.layoutInformation.ModelNO613);
            ListModel.Add(form1.layoutInformation.ModelNO614);
            ListModel.Add(form1.layoutInformation.ModelNO615);
            ListModel.Add(form1.layoutInformation.ModelNO616);
            ListModel.Add(form1.layoutInformation.ModelNO617);
            ListModel.Add(form1.layoutInformation.ModelNO618);
            ListModel.Add(form1.layoutInformation.ModelNO619);
            ListModel.Add(form1.layoutInformation.ModelNO620);

            ListModel.Add(form1.layoutInformation.ModelNO71);
            ListModel.Add(form1.layoutInformation.ModelNO72);
            ListModel.Add(form1.layoutInformation.ModelNO73);
            ListModel.Add(form1.layoutInformation.ModelNO74);
            ListModel.Add(form1.layoutInformation.ModelNO75);
            ListModel.Add(form1.layoutInformation.ModelNO76);
            ListModel.Add(form1.layoutInformation.ModelNO77);
            ListModel.Add(form1.layoutInformation.ModelNO78);
            ListModel.Add(form1.layoutInformation.ModelNO79);
            ListModel.Add(form1.layoutInformation.ModelNO710);
            ListModel.Add(form1.layoutInformation.ModelNO711);
            ListModel.Add(form1.layoutInformation.ModelNO712);
            ListModel.Add(form1.layoutInformation.ModelNO713);
            ListModel.Add(form1.layoutInformation.ModelNO714);
            ListModel.Add(form1.layoutInformation.ModelNO715);
            ListModel.Add(form1.layoutInformation.ModelNO716);
            ListModel.Add(form1.layoutInformation.ModelNO717);
            ListModel.Add(form1.layoutInformation.ModelNO718);
            ListModel.Add(form1.layoutInformation.ModelNO719);
            ListModel.Add(form1.layoutInformation.ModelNO720);

            ListModel.Add(form1.layoutInformation.ModelNO81);
            ListModel.Add(form1.layoutInformation.ModelNO82);
            ListModel.Add(form1.layoutInformation.ModelNO83);
            ListModel.Add(form1.layoutInformation.ModelNO84);
            ListModel.Add(form1.layoutInformation.ModelNO85);
            ListModel.Add(form1.layoutInformation.ModelNO86);
            ListModel.Add(form1.layoutInformation.ModelNO87);
            ListModel.Add(form1.layoutInformation.ModelNO88);
            ListModel.Add(form1.layoutInformation.ModelNO89);
            ListModel.Add(form1.layoutInformation.ModelNO810);
            ListModel.Add(form1.layoutInformation.ModelNO811);
            ListModel.Add(form1.layoutInformation.ModelNO812);
            ListModel.Add(form1.layoutInformation.ModelNO813);
            ListModel.Add(form1.layoutInformation.ModelNO814);
            ListModel.Add(form1.layoutInformation.ModelNO815);
            ListModel.Add(form1.layoutInformation.ModelNO816);
            ListModel.Add(form1.layoutInformation.ModelNO817);
            ListModel.Add(form1.layoutInformation.ModelNO818);
            ListModel.Add(form1.layoutInformation.ModelNO819);
            ListModel.Add(form1.layoutInformation.ModelNO820);

            ListModel.Add(form1.layoutInformation.ModelNO91);
            ListModel.Add(form1.layoutInformation.ModelNO92);
            ListModel.Add(form1.layoutInformation.ModelNO93);
            ListModel.Add(form1.layoutInformation.ModelNO94);
            ListModel.Add(form1.layoutInformation.ModelNO95);
            ListModel.Add(form1.layoutInformation.ModelNO96);
            ListModel.Add(form1.layoutInformation.ModelNO97);
            ListModel.Add(form1.layoutInformation.ModelNO98);
            ListModel.Add(form1.layoutInformation.ModelNO99);
            ListModel.Add(form1.layoutInformation.ModelNO910);
            ListModel.Add(form1.layoutInformation.ModelNO911);
            ListModel.Add(form1.layoutInformation.ModelNO912);
            ListModel.Add(form1.layoutInformation.ModelNO913);
            ListModel.Add(form1.layoutInformation.ModelNO914);
            ListModel.Add(form1.layoutInformation.ModelNO915);
            ListModel.Add(form1.layoutInformation.ModelNO916);
            ListModel.Add(form1.layoutInformation.ModelNO917);
            ListModel.Add(form1.layoutInformation.ModelNO918);
            ListModel.Add(form1.layoutInformation.ModelNO919);
            ListModel.Add(form1.layoutInformation.ModelNO920);

            ListModel.Add(form1.layoutInformation.ModelNO101);
            ListModel.Add(form1.layoutInformation.ModelNO102);
            ListModel.Add(form1.layoutInformation.ModelNO103);
            ListModel.Add(form1.layoutInformation.ModelNO104);
            ListModel.Add(form1.layoutInformation.ModelNO105);
            ListModel.Add(form1.layoutInformation.ModelNO106);
            ListModel.Add(form1.layoutInformation.ModelNO107);
            ListModel.Add(form1.layoutInformation.ModelNO108);
            ListModel.Add(form1.layoutInformation.ModelNO109);
            ListModel.Add(form1.layoutInformation.ModelNO1010);
            ListModel.Add(form1.layoutInformation.ModelNO1011);
            ListModel.Add(form1.layoutInformation.ModelNO1012);
            ListModel.Add(form1.layoutInformation.ModelNO1013);
            ListModel.Add(form1.layoutInformation.ModelNO1014);
            ListModel.Add(form1.layoutInformation.ModelNO1015);
            ListModel.Add(form1.layoutInformation.ModelNO1016);
            ListModel.Add(form1.layoutInformation.ModelNO1017);
            ListModel.Add(form1.layoutInformation.ModelNO1018);
            ListModel.Add(form1.layoutInformation.ModelNO1019);
            ListModel.Add(form1.layoutInformation.ModelNO1020);

            ListModel.Add(form1.layoutInformation.ModelNO1101);
            ListModel.Add(form1.layoutInformation.ModelNO1102);
            ListModel.Add(form1.layoutInformation.ModelNO1103);
            ListModel.Add(form1.layoutInformation.ModelNO1104);
            ListModel.Add(form1.layoutInformation.ModelNO1105);
            ListModel.Add(form1.layoutInformation.ModelNO1106);
            ListModel.Add(form1.layoutInformation.ModelNO1107);
            ListModel.Add(form1.layoutInformation.ModelNO1108);
            ListModel.Add(form1.layoutInformation.ModelNO1109);
            ListModel.Add(form1.layoutInformation.ModelNO1110);
            ListModel.Add(form1.layoutInformation.ModelNO1111);
            ListModel.Add(form1.layoutInformation.ModelNO1112);
            ListModel.Add(form1.layoutInformation.ModelNO1113);
            ListModel.Add(form1.layoutInformation.ModelNO1114);
            ListModel.Add(form1.layoutInformation.ModelNO1115);
            ListModel.Add(form1.layoutInformation.ModelNO1116);
            ListModel.Add(form1.layoutInformation.ModelNO1117);
            ListModel.Add(form1.layoutInformation.ModelNO1118);
            ListModel.Add(form1.layoutInformation.ModelNO1119);
            ListModel.Add(form1.layoutInformation.ModelNO1120);

            ListModel.Add(form1.layoutInformation.ModelNO1201);
            ListModel.Add(form1.layoutInformation.ModelNO1202);
            ListModel.Add(form1.layoutInformation.ModelNO1203);
            ListModel.Add(form1.layoutInformation.ModelNO1204);
            ListModel.Add(form1.layoutInformation.ModelNO1205);
            ListModel.Add(form1.layoutInformation.ModelNO1206);
            ListModel.Add(form1.layoutInformation.ModelNO1207);
            ListModel.Add(form1.layoutInformation.ModelNO1208);
            ListModel.Add(form1.layoutInformation.ModelNO1209);
            ListModel.Add(form1.layoutInformation.ModelNO1210);
            ListModel.Add(form1.layoutInformation.ModelNO1211);
            ListModel.Add(form1.layoutInformation.ModelNO1212);
            ListModel.Add(form1.layoutInformation.ModelNO1213);
            ListModel.Add(form1.layoutInformation.ModelNO1214);
            ListModel.Add(form1.layoutInformation.ModelNO1215);
            ListModel.Add(form1.layoutInformation.ModelNO1216);
            ListModel.Add(form1.layoutInformation.ModelNO1217);
            ListModel.Add(form1.layoutInformation.ModelNO1218);
            ListModel.Add(form1.layoutInformation.ModelNO1219);
            ListModel.Add(form1.layoutInformation.ModelNO1220);

            ListModel.Add(form1.layoutInformation.ModelNO1301);
            ListModel.Add(form1.layoutInformation.ModelNO1302);
            ListModel.Add(form1.layoutInformation.ModelNO1303);
            ListModel.Add(form1.layoutInformation.ModelNO1304);
            ListModel.Add(form1.layoutInformation.ModelNO1305);
            ListModel.Add(form1.layoutInformation.ModelNO1306);
            ListModel.Add(form1.layoutInformation.ModelNO1307);
            ListModel.Add(form1.layoutInformation.ModelNO1308);
            ListModel.Add(form1.layoutInformation.ModelNO1309);
            ListModel.Add(form1.layoutInformation.ModelNO1310);
            ListModel.Add(form1.layoutInformation.ModelNO1311);
            ListModel.Add(form1.layoutInformation.ModelNO1312);
            ListModel.Add(form1.layoutInformation.ModelNO1313);
            ListModel.Add(form1.layoutInformation.ModelNO1314);
            ListModel.Add(form1.layoutInformation.ModelNO1315);
            ListModel.Add(form1.layoutInformation.ModelNO1316);
            ListModel.Add(form1.layoutInformation.ModelNO1317);
            ListModel.Add(form1.layoutInformation.ModelNO1318);
            ListModel.Add(form1.layoutInformation.ModelNO1319);
            ListModel.Add(form1.layoutInformation.ModelNO1320);

            ListModel.Add(form1.layoutInformation.ModelNO1401);
            ListModel.Add(form1.layoutInformation.ModelNO1402);
            ListModel.Add(form1.layoutInformation.ModelNO1403);
            ListModel.Add(form1.layoutInformation.ModelNO1404);
            ListModel.Add(form1.layoutInformation.ModelNO1405);
            ListModel.Add(form1.layoutInformation.ModelNO1406);
            ListModel.Add(form1.layoutInformation.ModelNO1407);
            ListModel.Add(form1.layoutInformation.ModelNO1408);
            ListModel.Add(form1.layoutInformation.ModelNO1409);
            ListModel.Add(form1.layoutInformation.ModelNO1410);
            ListModel.Add(form1.layoutInformation.ModelNO1411);
            ListModel.Add(form1.layoutInformation.ModelNO1412);
            ListModel.Add(form1.layoutInformation.ModelNO1413);
            ListModel.Add(form1.layoutInformation.ModelNO1414);
            ListModel.Add(form1.layoutInformation.ModelNO1415);
            ListModel.Add(form1.layoutInformation.ModelNO1416);
            ListModel.Add(form1.layoutInformation.ModelNO1417);
            ListModel.Add(form1.layoutInformation.ModelNO1418);
            ListModel.Add(form1.layoutInformation.ModelNO1419);
            ListModel.Add(form1.layoutInformation.ModelNO1420);

            ListModel.Add(form1.layoutInformation.ModelNO1501);
            ListModel.Add(form1.layoutInformation.ModelNO1502);
            ListModel.Add(form1.layoutInformation.ModelNO1503);
            ListModel.Add(form1.layoutInformation.ModelNO1504);
            ListModel.Add(form1.layoutInformation.ModelNO1505);
            ListModel.Add(form1.layoutInformation.ModelNO1506);
            ListModel.Add(form1.layoutInformation.ModelNO1507);
            ListModel.Add(form1.layoutInformation.ModelNO1508);
            ListModel.Add(form1.layoutInformation.ModelNO1509);
            ListModel.Add(form1.layoutInformation.ModelNO1510);
            ListModel.Add(form1.layoutInformation.ModelNO1511);
            ListModel.Add(form1.layoutInformation.ModelNO1512);
            ListModel.Add(form1.layoutInformation.ModelNO1513);
            ListModel.Add(form1.layoutInformation.ModelNO1514);
            ListModel.Add(form1.layoutInformation.ModelNO1515);
            ListModel.Add(form1.layoutInformation.ModelNO1516);
            ListModel.Add(form1.layoutInformation.ModelNO1517);
            ListModel.Add(form1.layoutInformation.ModelNO1518);
            ListModel.Add(form1.layoutInformation.ModelNO1519);
            ListModel.Add(form1.layoutInformation.ModelNO1520);

            ListModel.Add(form1.layoutInformation.ModelNO1601);
            ListModel.Add(form1.layoutInformation.ModelNO1602);
            ListModel.Add(form1.layoutInformation.ModelNO1603);
            ListModel.Add(form1.layoutInformation.ModelNO1604);
            ListModel.Add(form1.layoutInformation.ModelNO1605);
            ListModel.Add(form1.layoutInformation.ModelNO1606);
            ListModel.Add(form1.layoutInformation.ModelNO1607);
            ListModel.Add(form1.layoutInformation.ModelNO1608);
            ListModel.Add(form1.layoutInformation.ModelNO1609);
            ListModel.Add(form1.layoutInformation.ModelNO1610);
            ListModel.Add(form1.layoutInformation.ModelNO1611);
            ListModel.Add(form1.layoutInformation.ModelNO1612);
            ListModel.Add(form1.layoutInformation.ModelNO1613);
            ListModel.Add(form1.layoutInformation.ModelNO1614);
            ListModel.Add(form1.layoutInformation.ModelNO1615);
            ListModel.Add(form1.layoutInformation.ModelNO1616);
            ListModel.Add(form1.layoutInformation.ModelNO1617);
            ListModel.Add(form1.layoutInformation.ModelNO1618);
            ListModel.Add(form1.layoutInformation.ModelNO1619);
            ListModel.Add(form1.layoutInformation.ModelNO1620);

            ListModel.Add(form1.layoutInformation.ModelNO1701);
            ListModel.Add(form1.layoutInformation.ModelNO1702);
            ListModel.Add(form1.layoutInformation.ModelNO1703);
            ListModel.Add(form1.layoutInformation.ModelNO1704);
            ListModel.Add(form1.layoutInformation.ModelNO1705);
            ListModel.Add(form1.layoutInformation.ModelNO1706);
            ListModel.Add(form1.layoutInformation.ModelNO1707);
            ListModel.Add(form1.layoutInformation.ModelNO1708);
            ListModel.Add(form1.layoutInformation.ModelNO1709);
            ListModel.Add(form1.layoutInformation.ModelNO1710);
            ListModel.Add(form1.layoutInformation.ModelNO1711);
            ListModel.Add(form1.layoutInformation.ModelNO1712);
            ListModel.Add(form1.layoutInformation.ModelNO1713);
            ListModel.Add(form1.layoutInformation.ModelNO1714);
            ListModel.Add(form1.layoutInformation.ModelNO1715);
            ListModel.Add(form1.layoutInformation.ModelNO1716);
            ListModel.Add(form1.layoutInformation.ModelNO1717);
            ListModel.Add(form1.layoutInformation.ModelNO1718);
            ListModel.Add(form1.layoutInformation.ModelNO1719);
            ListModel.Add(form1.layoutInformation.ModelNO1720);

            ListModel.Add(form1.layoutInformation.ModelNO1801);
            ListModel.Add(form1.layoutInformation.ModelNO1802);
            ListModel.Add(form1.layoutInformation.ModelNO1803);
            ListModel.Add(form1.layoutInformation.ModelNO1804);
            ListModel.Add(form1.layoutInformation.ModelNO1805);
            ListModel.Add(form1.layoutInformation.ModelNO1806);
            ListModel.Add(form1.layoutInformation.ModelNO1807);
            ListModel.Add(form1.layoutInformation.ModelNO1808);
            ListModel.Add(form1.layoutInformation.ModelNO1809);
            ListModel.Add(form1.layoutInformation.ModelNO1810);
            ListModel.Add(form1.layoutInformation.ModelNO1811);
            ListModel.Add(form1.layoutInformation.ModelNO1812);
            ListModel.Add(form1.layoutInformation.ModelNO1813);
            ListModel.Add(form1.layoutInformation.ModelNO1814);
            ListModel.Add(form1.layoutInformation.ModelNO1815);
            ListModel.Add(form1.layoutInformation.ModelNO1816);
            ListModel.Add(form1.layoutInformation.ModelNO1817);
            ListModel.Add(form1.layoutInformation.ModelNO1818);
            ListModel.Add(form1.layoutInformation.ModelNO1819);
            ListModel.Add(form1.layoutInformation.ModelNO1820);

            ListModel.Add(form1.layoutInformation.ModelNO1901);
            ListModel.Add(form1.layoutInformation.ModelNO1902);
            ListModel.Add(form1.layoutInformation.ModelNO1903);
            ListModel.Add(form1.layoutInformation.ModelNO1904);
            ListModel.Add(form1.layoutInformation.ModelNO1905);
            ListModel.Add(form1.layoutInformation.ModelNO1906);
            ListModel.Add(form1.layoutInformation.ModelNO1907);
            ListModel.Add(form1.layoutInformation.ModelNO1908);
            ListModel.Add(form1.layoutInformation.ModelNO1909);
            ListModel.Add(form1.layoutInformation.ModelNO1910);
            ListModel.Add(form1.layoutInformation.ModelNO1911);
            ListModel.Add(form1.layoutInformation.ModelNO1912);
            ListModel.Add(form1.layoutInformation.ModelNO1913);
            ListModel.Add(form1.layoutInformation.ModelNO1914);
            ListModel.Add(form1.layoutInformation.ModelNO1915);
            ListModel.Add(form1.layoutInformation.ModelNO1916);
            ListModel.Add(form1.layoutInformation.ModelNO1917);
            ListModel.Add(form1.layoutInformation.ModelNO1918);
            ListModel.Add(form1.layoutInformation.ModelNO1919);
            ListModel.Add(form1.layoutInformation.ModelNO1920);

            ListModel.Add(form1.layoutInformation.ModelNO2001);
            ListModel.Add(form1.layoutInformation.ModelNO2002);
            ListModel.Add(form1.layoutInformation.ModelNO2003);
            ListModel.Add(form1.layoutInformation.ModelNO2004);
            ListModel.Add(form1.layoutInformation.ModelNO2005);
            ListModel.Add(form1.layoutInformation.ModelNO2006);
            ListModel.Add(form1.layoutInformation.ModelNO2007);
            ListModel.Add(form1.layoutInformation.ModelNO2008);
            ListModel.Add(form1.layoutInformation.ModelNO2009);
            ListModel.Add(form1.layoutInformation.ModelNO2010);
            ListModel.Add(form1.layoutInformation.ModelNO2011);
            ListModel.Add(form1.layoutInformation.ModelNO2012);
            ListModel.Add(form1.layoutInformation.ModelNO2013);
            ListModel.Add(form1.layoutInformation.ModelNO2014);
            ListModel.Add(form1.layoutInformation.ModelNO2015);
            ListModel.Add(form1.layoutInformation.ModelNO2016);
            ListModel.Add(form1.layoutInformation.ModelNO2017);
            ListModel.Add(form1.layoutInformation.ModelNO2018);
            ListModel.Add(form1.layoutInformation.ModelNO2019);
            ListModel.Add(form1.layoutInformation.ModelNO2020);

            CreateButtonMatrix(form1.layoutInformation.ProductRows, form1.layoutInformation.ProductCols, form1.layoutInformation.layers);
            CreatetableLayoutPanelRow(form1.layoutInformation.layers);
            GetProductUseModel();
        }
        public void CreateButtonMatrix(int rows, int cols, int spacing)
        {
            int buttonSize = 30;
            // 清除Panel中原有的控件
            panel1.Controls.Clear();
            int startX = 0;
            int spacingY = 0;
            int spacingX = 0;
            int startY = 0;
            decimal x = panel1.Width / cols;
            decimal y = panel1.Height / rows;
            decimal buttonSizeX = Math.Truncate(x);
            decimal buttonSizey = Math.Truncate(y);
            buttonSize = Convert.ToInt16(Math.Min(buttonSizeX, buttonSizey)) - spacing;

            // 计算起始位置使矩阵居中    
            if (cols >= rows)
            {
                startX = (panel1.Width - (cols * (buttonSize + spacing))) / 2;
                spacingY = (panel1.Height - startX - buttonSize * rows) / (rows + 1);
                startY = (panel1.Height - (rows * (buttonSize + spacingY))) / 2;
            }
            else
            {
                startY = (panel1.Height - (rows * (buttonSize + spacing))) / 2;
                spacingX = (panel1.Width - startY - buttonSize * cols) / (cols + 1);
                startX = (panel1.Width - (cols * (buttonSize + spacingX))) / 2;
            }

            // 创建按钮矩阵
            for (int row = 0; row < rows; row++)
            {
                for (int col = 0; col < cols; col++)
                {
                    UILight btn = new UILight();
                    btn.Size = new Size(buttonSize, buttonSize);
                    if (cols >= rows)
                    {
                        btn.Location = new Point(
                       startX + col * (buttonSize + spacing),
                       startY + row * (buttonSize + spacingY));
                    }

                    else
                    {
                        btn.Location = new Point(
                    startX + col * (buttonSize + spacingX),
                    startY + row * (buttonSize + spacing));
                    }

                    btn.Text = $"{row},{col}";
                    btn.Tag = new Point(row, col); // 存储行列信息

                    // 添加点击事件
                    btn.Click += (sender, e) =>
                    {
                        UILight clickedBtn = (UILight)sender;
                        //clickedBtn.OnColor = Color.DarkMagenta;
                        Chosedposition = (Point)clickedBtn.Tag;
                        
                        for (int i = 0; i < listTextBox.Count; i++)//listTextBox层数显示模板
                        {
                         listTextBox[i].Text = ListModel[Chosedposition.X + 20 * i][Chosedposition.Y].ToString();
                                         
                        }

                        ChosedLabel.Text = "行：" + (Chosedposition.X+1).ToString()+ " 列: " + (Chosedposition.Y+1).ToString();                       
                        //MessageBox.Show($"你点击了: 行{Chosedposition.X} 列{Chosedposition.Y}");
                    };

                    panel1.Controls.Add(btn);
                }
            }

        }

        public bool UpdataLayerStyle(int rows, int cols, int layers)
        {
         if (layers > 0)
           {           
            for (int i = 1; i <= layers; i++)//层数
            {
                    if (int.TryParse(listTextBox[i-1].Text,out int result))
                    {

                        if (result>8)
                        {
                            MessageBox.Show("输入模板编号不正确");
                            return false;
                        }

                        listlayerText[i - 1] = result;
                    }

                 ListModel[rows+20*(i-1)][cols] = listlayerText[i-1];
           
            }
                return true;
            }
            else
            {
                return false;
            }
        }

        private void LayoutForm_Load(object sender, EventArgs e)
        {

        }
       
        private void CreatetableLayoutPanelRow(int rows)
        {
            float FontHeight = 0;
            tableLayoutPanel1.Size = new System.Drawing.Size(70, 25);
            tableLayoutPanel1.Size = new Size(tableLayoutPanel1.Width, tableLayoutPanel1.Height * rows);
            tableLayoutPanel1.RowCount = rows;
            tableLayoutPanel1.ColumnCount = 1;
            // 清除现有样式
            tableLayoutPanel1.RowStyles.Clear();
            tableLayoutPanel1.ColumnStyles.Clear();
            tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100f));       
            for (int i = 0; i < rows; i++)
            {
                tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 100f / rows));

                // 创建TextBox
                 textBox = new UITextBox
                {
                    Name = "LayertextBox" + i.ToString(),
                    Dock = DockStyle.Top,
                    Multiline = true,
                    Margin = new Padding(2),
                    Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom                

            };
                listTextBox.Add(textBox);
                // 添加点击事件
                textBox.MouseClick += (sender, e) =>
                {
                    for (int j = 0; j < listTextBox.Count; j++)
                    {
                        if (int.TryParse(listTextBox[j].Text, out int result))
                        {
                            listlayerText[j] = result;   
                            
                        }
                        listTextBox[j].Text = listlayerText[j].ToString();
                        //switch (j)
                        //{
                        //    case 0:
                        //        if (int.TryParse(textBox.Text, out int result1))
                        //        {
                        //            listlayerText[0] = result1;
                        //        }

                        //        break;
                        //    case 1:
                        //        if (int.TryParse(textBox.Text, out int result2))
                        //        {
                        //            listlayerText[1] = result2;
                        //        }

                        //        break;
                        //    case 2:
                        //        if (int.TryParse(textBox.Text, out int result3))
                        //        {
                        //            listlayerText[2] = result3;
                        //        }

                        //        break;
                        //    case 3:
                        //        if (int.TryParse(textBox.Text, out int result4))
                        //        {
                        //            listlayerText[3] = result4;
                        //        }

                        //        break;
                        //    case 4:
                        //        if (int.TryParse(textBox.Text, out int result5))
                        //        {
                        //            listlayerText[4] = result5;
                        //        }

                        //        break;
                        //    case 5:
                        //        if (int.TryParse(textBox.Text, out int result6))
                        //        {
                        //            listlayerText[5] = result6;
                        //        }

                        //        break;
                        //    case 6:
                        //        if (int.TryParse(textBox.Text, out int result7))
                        //        {
                        //            listlayerText[6] = result7;
                        //        }

                        //        break;
                        //    case 7:
                        //        if (int.TryParse(textBox.Text, out int result8))
                        //        {
                        //            listlayerText[7] = result8;
                        //        }

                        //        break;
                        //    case 8:
                        //        if (int.TryParse(textBox.Text, out int result9))
                        //        {
                        //            listlayerText[8] = result9;
                        //        }

                        //        break;
                        //    case 9:
                        //        if (int.TryParse(textBox.Text, out int result10))
                        //        {
                        //            listlayerText[9] = result10;
                        //        }

                        //        break;

                        //}
                    }
                    //MessageBox.Show($"你点击了: 高{layerText1}");
                };

                if (i == 0)
                {
                    FontHeight = (float)(textBox.Size.Height * 0.3);
                  
                }
                textBox.Font = new Font("微软雅黑", FontHeight);
                // 将TextBox添加到表格中（列0，行i）
                tableLayoutPanel1.Controls.Add(textBox, 0, i);
            }

            tableLayoutPanel1.ResumeLayout(true);


        }

        public List<int> CombineListModel(List<List<int>> ListModel,int rows,int cols,int layers)
        {
            List<int> CombineList = new List<int>();
            for (int i = 0; i < layers; i++)
            {
                for (int j = 0; j < rows; j++)                    
                {
                    for (int k = 0; k < cols; k++)
                    {
                        CombineList.Add(ListModel[j + 20 * i][k]);
                    }
                }
            }

            return CombineList;
        }

        private void btn_ForAll_Click(object sender, EventArgs e)
        {
            DialogResult Result = MessageBox.Show(this, "确定将当前点位模板应用到所用点位？", "应用到所有", MessageBoxButtons.OKCancel);
            if (Result == DialogResult.OK)
            {
                for (int i = 0; i < listTextBox.Count; i++)//listTextBox层数显示模板
                {

                    if (int.TryParse(listTextBox[i].Text, out int result))
                    {
                        if (result>8 )
                        {
                            MessageBox.Show("输入模板编号不正确");
                            return;
                        }
                        for (int j = 0; j < 20; j++)
                        {
                            for (int k = 0; k < 20; k++)
                            {
                                ListModel[j + 20 * i][k] = result;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("输入模板编号不正确");
                        return;
                    }
                }
                form1.WritelayoutInformation(Application.StartupPath + @"\LayoutInformation\"+ form1.layoutInformation.CurrentMaterial + @"\LayoutInformation.config");
            }
        }

        private void SetProductUseModel()
        {
            form1.layoutInformation.ProductTypeUsed[0] = cbWorkstation1.Checked;
            form1.layoutInformation.ProductTypeUsed[1] = cbWorkstation2.Checked;
            form1.layoutInformation.ProductTypeUsed[2] = cbWorkstation3.Checked;
            form1.layoutInformation.ProductTypeUsed[3] = cbWorkstation4.Checked;
            form1.layoutInformation.ProductTypeUsed[4] = cbWorkstation5.Checked;
            form1.layoutInformation.ProductTypeUsed[5] = cbWorkstation6.Checked;
            form1.layoutInformation.ProductTypeUsed[6] = cbWorkstation7.Checked;
            form1.layoutInformation.ProductTypeUsed[7] = cbWorkstation8.Checked;          
        }

        public void GetProductUseModel()
        {

            cbWorkstation1.Checked = form1.layoutInformation.ProductTypeUsed[0];
            cbWorkstation2.Checked = form1.layoutInformation.ProductTypeUsed[1];
            cbWorkstation3.Checked = form1.layoutInformation.ProductTypeUsed[2];
            cbWorkstation4.Checked = form1.layoutInformation.ProductTypeUsed[3];
            cbWorkstation5.Checked = form1.layoutInformation.ProductTypeUsed[4];
            cbWorkstation6.Checked = form1.layoutInformation.ProductTypeUsed[5];
            cbWorkstation7.Checked = form1.layoutInformation.ProductTypeUsed[6];
            cbWorkstation8.Checked = form1.layoutInformation.ProductTypeUsed[7];
        
    }

        private void btnParameterSet_Click(object sender, EventArgs e)
        {
            SetProductUseModel();
            if (UpdataLayerStyle(Chosedposition.X, Chosedposition.Y, form1.layoutInformation.layers) &&
            form1.WritelayoutInformation(Application.StartupPath + @"\LayoutInformation\" + form1.layoutInformation.CurrentMaterial +@"\LayoutInformation.config"))
            {
                MessageBox.Show("保存成功");
            }     
            

        }
    }

}
